//
//  KYMenuView.m
//  kuaiyi
//
//  Created by ake on 16/5/3.
//
//

#import "YZMenuView.h"
#import "YZMenuTableViewCell.h"
#import "YZAboutProductTableViewController.h"
#import "YZManagerViewController.h"
#import "YZDoctorApplicantViewController.h"
#import "YZAttDocTableViewController.h"
#import "YZSettingHelpTableViewController.h"
#import "YZHasLoginMenuHeaderView.h"

@interface YZMenuView () <UITableViewDataSource , UITableViewDelegate>
@property (nonatomic,strong)UITableView *tableView;
//菜单所有 cell 对应的数组
@property (nonatomic,strong)NSArray *menuArr;
@property (nonatomic ,assign)NSInteger rowCount;

@end
@implementation YZMenuView

-(void)awakeFromNib{
    //设置XIB 中自己的 frame
    CGRect screenBounds = [UIScreen mainScreen].bounds;
    self.frame = CGRectMake(0, 0, 300,screenBounds.size.height);
    
    //创建tableView
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 300, screenBounds.size.height) style:UITableViewStyleGrouped];
    self.rowCount = 3;
    self.tableView = tableView;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0);
    [self addSubview:tableView];
    
    
    //添加 tableViewHeaderView
    YZHasLoginMenuHeaderView *tableHeaderView =[[[NSBundle mainBundle]loadNibNamed:@"YZHasLoginMenuHeaderView" owner:nil options:nil]lastObject];
     //给 tableHeaderView 添加一个单击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(personalSettingBtnDidClick)];
    [tableHeaderView addGestureRecognizer:tap];
    self.tableView.tableHeaderView = tableHeaderView;

    //创建列表数组
    NSDictionary *doctorApplicant = @{@"name":@"名医通申请" , @"vcClass":[YZDoctorApplicantViewController class]};
    NSDictionary *caseHistory = @{@"name":@"病历管理" , @"vcClass":[YZManagerViewController class]};
    NSDictionary *aboutDoctor = @{@"name":@"关注医生" , @"vcClass":[YZAttDocTableViewController class]};
    NSDictionary *settingHelp = @{@"name":@"设置与帮助" , @"vcClass":[YZSettingHelpTableViewController class]};
    NSDictionary *aboutProduct = @{@"name":@"关于产品" , @"vcClass":[YZAboutProductTableViewController class]};
    NSDictionary *share = @{@"name":@"分享给好友" , @"vcClass":[UIButton class]};
    NSArray *menuArr = [NSArray arrayWithObjects:doctorApplicant,caseHistory,aboutDoctor,settingHelp,aboutProduct,share, nil];
    self.menuArr = menuArr;
    
}

#pragma mark - 跳转基本资料信息
-(void)personalSettingBtnDidClick{
    self.personalSettingBtnDidClickBlock();
}


#pragma mark - tableView 数据源方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YZMenuTableViewCell *cell = [[[NSBundle mainBundle]loadNibNamed:@"YZMenuTableViewCell" owner:nil options:nil]lastObject];
    NSDictionary *dict = self.menuArr[indexPath.section*self.rowCount+indexPath.row];
    [cell setupCell:dict];
    return cell;
}

#pragma mark - tableview delegate 方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *selectedDict = self.menuArr[indexPath.section*self.rowCount+indexPath.row];
    self.cellDidClickBlock((Class)selectedDict[@"vcClass"]);
}



@end
